//
//  orderListsViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/26.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "TradesViewController.h"
#import "OrderDetailViewController.h"


#import "UIImageView+WebCache.h"
#import "shouyingViewController.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "sxview.h"
#import "orderListCell.h"
#import "OrderDetailViewController.H"
#import "ServiceDetailViewController.H"
#import "RefundDetailViewController.H"

#import "TheLoginViewController.h"

#import "PlaceOrderViewController.h"
@interface TradesViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UISearchBarDelegate>
@property (strong, nonatomic) NSString *areaValue;
@property (strong, nonatomic) NSString*cityValue;
@property (retain, nonatomic)NSString*sats;
@property (retain, nonatomic)NSString*orderSort;
@property(nonatomic,retain)UIDatePicker* da;
@end

@implementation TradesViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    MJRefreshHeaderView* _header;
    MJRefreshFooterView* _footer;
    
    NSMutableArray*DocNum;
    NSMutableArray*DocDate;
    NSMutableArray*DocTotal;
    NSMutableArray*ItemName;
    NSMutableArray*Number;
    NSMutableArray*orderType;
    NSMutableArray* GuideCode;
    NSMutableArray* GuideName;
    NSMutableArray* MemberCode;
    NSMutableArray* MemberName;
    NSMutableArray* orderId;
    NSMutableArray* itemTypes;
    NSMutableArray* earnestMoney;
    NSMutableArray*orderStatus;
    NSMutableArray*installStatus;
    NSMutableArray*deliveryStatus;
    NSMutableArray*payStatus;
    NSMutableArray*serviceType;
    NSMutableArray*serviceStatus;
    NSMutableArray*reasonType;
    NSMutableArray*refundType;
    NSMutableArray*refundStatus;

    BOOL saveAccount;
    BOOL saveAccount1;
    NSString *result;
    int pageNumber;
    MBProgressHUD *progressHud;
    UIView* backview1;
    UIScrollView*myscrollView;
    NSString* sous;
    int pageNumber1;
    int pageNumber2;
    NSString*meiyousuos;
    UIView*view3;
    UITextField*searchTextField;
    UITextField*telTextFied;
    UITextField*zbsTextFied;
    UITextField*zbsTextFied1;
    UITextField*gjzFied;
    UITextField*Salary1;
    UITextField*WorkExper1;
    UIView *view1;
    UIView *view2;
    UIButton*sat;
    UIButton*sat1;
    UIButton*btn2;
    UIView*myToolBar1;
    UIButton* sxBtn;
    UIButton*jiazai;
    float lastContentOffset;
    UIButton*i22;
    UIButton*i1;
    UIButton*i12;
    UIButton*jiantouNormal;
    NSString*TotalCount;
    UIButton*shuliang;
    UIView*tableHeaderViews;
    NSMutableArray*typeName;
    NSMutableArray*typeCode;
    NSMutableArray*isSingle;
    NSMutableArray*congzhicurrent;
    NSMutableArray*current;
    NSMutableArray*dataType;
    NSMutableArray *searchBeans;
    NSMutableArray*itemValue;
    NSMutableArray*itemName;
    NSMutableArray*items;
    UITextField*openTimeTextFied;
    UITextField*closeTimeTextFied;
    sxview*daogouView;
    UIView*view;
    UITableView *table_list;
    UIScrollView*mainScroll;
    NSMutableArray* arrrss;
    UIButton*shaixuanBtn;
}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    
     [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSLog(@"tttt");
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    
    self.title=@"交易明细";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    [self add];
    
    // 手势
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [myscrollView addGestureRecognizer:singleFingerOne];
    
    UIView* myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    searchTextField.inputAccessoryView = myToolBar;
    
}

-(void)OnTapDone{
    
    [searchTextField resignFirstResponder];
    
    [self add];
    
    
}



- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    [self addFooter];
    
    [self addheader];
    
    self.sats=@"newOrder";
    _orderSort=@"desc";
    
    typeCode=[[NSMutableArray alloc]init];
    typeName=[[NSMutableArray alloc]init];
    items=[[NSMutableArray alloc]init];
    isSingle=[[NSMutableArray alloc]init];
    current=[[NSMutableArray alloc]init];
    congzhicurrent=[[NSMutableArray alloc]init];
    dataType=[[NSMutableArray alloc]init];
    
    commdity=[HAODEsingleton shared];
    commdity.opentime=nil;
    commdity.closeTime=nil;
    commdity.content3=@"";
    
    tableHeaderViews=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,80/2)];
    tableHeaderViews.backgroundColor= zuiqianhuicolor;
    
    _table.delegate=self;
    _table.dataSource=self;
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    _table.tableHeaderView=tableHeaderViews;
    
    shuliang=[[UIButton alloc]initWithFrame:CGRectMake(5, 0, ScreenWidth*430/750, 80/2)];
    //  shuliang.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
    [shuliang setTitleColor:shenhuicolor forState:UIControlStateNormal];
    shuliang.titleLabel.font=[UIFont systemFontOfSize:14];
    shuliang.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [tableHeaderViews addSubview:shuliang];

    
    
    
    shaixuanBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-78,  0, 60,40)];
    [shaixuanBtn.layer setCornerRadius:2.0];
    [shaixuanBtn.layer setBorderWidth:0];
    [shaixuanBtn.layer setMasksToBounds:YES];
    [shaixuanBtn addTarget:self action:@selector(sxuan:) forControlEvents:UIControlEventTouchUpInside];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){153/255.0,153/255.0, 153/255.0, 1.0   });
    [shaixuanBtn.layer setBorderColor:colorref2];//边框颜色
    [shaixuanBtn setTitle:@"筛选" forState:UIControlStateNormal];
    shaixuanBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [shaixuanBtn setTitleColor:shenhuicolor forState:UIControlStateNormal];
    shaixuanBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    [tableHeaderViews addSubview:shaixuanBtn];
    
    sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(3.5,5, 30, 30)];
    [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
    [sxBtn addTarget:self action:@selector(sxuan:) forControlEvents:UIControlEventTouchUpInside];
    [shaixuanBtn addSubview:sxBtn];
    
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"order" forKey:@"filterType"];
    NSLog(@"====%@",param);
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Common/AdvancedFilterList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====－－－－－－－%@",severDataDict.dataDict);
            
            
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                
                for (NSDictionary* dicc in arrr )
                {
                    [typeName addObject:[dicc valueForKey:@"typeName"]];
                    [typeCode addObject:[dicc valueForKey:@"typeCode"]];
                    [items addObject:[dicc valueForKey:@"items"]];
                    [isSingle addObject:[dicc valueForKey:@"isSingle"]];
                    
                    [congzhicurrent addObject:[dicc valueForKey:@"current"]];
                    [current addObject:[dicc valueForKey:@"current"]];
                    [dataType addObject:[dicc valueForKey:@"dataType"]];
                    
                    for (NSDictionary* dicc1 in items )
                    {
                        [itemName addObject:[dicc1 valueForKey:@"itemName"]];
                        [itemValue addObject:[dicc1 valueForKey:@"itemValue"]];
                        
                    }
                    
                    
                }
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
}
-(void)add{
    
    
    
   
    MemberName= [[NSMutableArray alloc] init];
    MemberCode= [[NSMutableArray alloc] init];
    GuideName= [[NSMutableArray alloc] init];
    GuideCode= [[NSMutableArray alloc] init];
    orderType= [[NSMutableArray alloc] init];
    Number= [[NSMutableArray alloc] init];
    ItemName= [[NSMutableArray alloc] init];
    DocTotal = [[NSMutableArray alloc] init];
    DocDate = [[NSMutableArray alloc] init];
    DocNum = [[NSMutableArray alloc] init];
    orderStatus = [[NSMutableArray alloc] init];
    installStatus = [[NSMutableArray alloc] init];
    deliveryStatus = [[NSMutableArray alloc] init];
    payStatus = [[NSMutableArray alloc] init];
    serviceType = [[NSMutableArray alloc] init];
    serviceStatus = [[NSMutableArray alloc] init];
    reasonType = [[NSMutableArray alloc] init];
    refundType = [[NSMutableArray alloc] init];
    refundStatus = [[NSMutableArray alloc] init];
    orderId = [[NSMutableArray alloc] init];
    itemTypes= [[NSMutableArray alloc] init];
    earnestMoney= [[NSMutableArray alloc] init];
    

    
    pageNumber = 1;
    
    
    
    
    commdity=[HAODEsingleton shared];
    
    meiyousuos=@"meiyou";
    sous=nil;
    
    NSUserDefaults *user11 = [NSUserDefaults standardUserDefaults];
    NSString* Token11 = [user11 objectForKey:@"tokenId"];
    NSMutableDictionary *param11 = [NSMutableDictionary new];
    [param11 setValue:Token11 forKey:@"tokenId"];
    [param11 setValue:commdity.memberId forKey:@"memberId"];
    [param11 setValue:@"1" forKey:@"PageIndex"];
    [param11 setValue:@"50" forKey:@"PageSize"];
//  [param setValue:searchBeans forKey:@"searchBeans"];
    NSLog(@"====%@",param11);
    
    [HttpRequest requestData:@"Business/Member/Trades" params:param11 success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
  
    
            NSLog(@"====%@",severDataDict.dataDict);
            
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                if (searchBeans.count>0) {
                    
                    UIImage *img=[UIImage imageNamed:@"shaixuan_hight"];
                UIImage *tinted = [img rt_tintedImageWithColor:luseColor];
                [shaixuanBtn setTitleColor:luseColor forState:UIControlStateNormal];
                [sxBtn setImage:tinted forState:UIControlStateNormal];
                    
                    
                }else{
                    [shaixuanBtn setTitleColor:shenhuicolor forState:UIControlStateNormal];
                    [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
                }
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                
                if (arrr.count>0) {
                    NSString*GoldPrice=[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"totalMoney"]];
                    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                    [numberFormatter setPositiveFormat:@"###,##0.00;"];
                    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];

                    TotalCount=[severDataDict.dataDict objectForKey:@"TotalCount"];
                    [shuliang setTitle:[NSString stringWithFormat:@"   共 %@ 条 ¥%@",TotalCount,formattedNumberString] forState:UIControlStateNormal];

//                    tableHeaderViews
                    
                    for (NSDictionary* dicc in arrr )
                    {
                        [DocNum addObject:[dicc valueForKey:@"orderNo"]];
                        [orderId addObject:[dicc valueForKey:@"orderId"]];
                        [DocDate addObject:[dicc valueForKey:@"orderDate"]];
                        [DocTotal addObject:[dicc valueForKey:@"realMoney"]];
                        [ItemName addObject:[dicc valueForKey:@"itemTypes"]];
                        [Number addObject:[dicc valueForKey:@"totalQuantity"]];
                        [orderType addObject:[dicc valueForKey:@"orderType"]];
                        [GuideName addObject:[dicc valueForKey:@"memberName"]];
                        [itemTypes addObject:[dicc valueForKey:@"itemTypes"]];
                        
                        [earnestMoney addObject:[dicc valueForKey:@"earnestMoney"]];
                        [orderStatus addObject:[dicc valueForKey:@"orderStatus"]];
                        [installStatus addObject:[dicc valueForKey:@"installStatus"]];
                        [deliveryStatus addObject:[dicc valueForKey:@"deliveryStatus"]];
                        [payStatus addObject:[dicc valueForKey:@"payStatus"]];
                        [serviceType addObject:[dicc valueForKey:@"serviceType"]];
                        [serviceStatus addObject:[dicc valueForKey:@"serviceStatus"]];
                        [reasonType addObject:[dicc valueForKey:@"reasonType"]];
                        [refundType addObject:[dicc valueForKey:@"refundType"]];
                        [refundStatus addObject:[dicc valueForKey:@"refundStatus"]];
                        
                        
                        
                    }
                    [_table reloadData];
                    
                }
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                    
                    TheLoginViewController *detailViewController = [[TheLoginViewController alloc] init];
                    [self.navigationController pushViewController:detailViewController animated:YES];
                }
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
    
}

-(void)sat:(UIButton*)sender{
    [sat1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [sat setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    searchBeans=nil;
    self.sats=@"newOrder";
    [self add];
}
-(void)sat1:(UIButton*)sender{
    saveAccount=!saveAccount;
    if (saveAccount) {
        
        self.sats=@"amount";
        
        _orderSort=@"desc";
        [self add];
        [sat setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [sat1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [jiantouNormal setImage:[UIImage imageNamed:@"shang_hight"] forState:UIControlStateNormal];
        
    }else{
        
        self.sats=@"amount";
        
        _orderSort=@"asc";
        [self add];
        [sat setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [sat1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [jiantouNormal setImage:[UIImage imageNamed:@"xia_hight"] forState:UIControlStateNormal];
        
    }
}


//下拉刷新
- (void)addheader
{
    
    //
    
    
    
    MJRefreshHeaderView* footer = [MJRefreshHeaderView header];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        searchBeans=nil;
        self.sats=@"newOrder";
        commdity.content3=@"";
        
        [self add];
        
        
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
}



//上拉刷新
- (void)addFooter
{
    
    
    MJRefreshFooterView* footer = [MJRefreshFooterView footer];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        
        
        
        
        
              [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
}
- (void)doneWithView:(MJRefreshBaseView *)refreshView
{
    [_table reloadData];
    [refreshView endRefreshing];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (tableView == table_list) {
        return [typeCode count];
    }
    return [DocNum count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    orderListCell* cell = (orderListCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"orderListCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(0,0, 8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    
    if (tableView == _table) {
        
        NSString *s21 = [NSString stringWithFormat:@"%@",  [DocNum objectAtIndex:indexPath.row]];
        UIFont *font21 = [UIFont systemFontOfSize:titleNemberfot];
        CGSize size21 = CGSizeMake(ScreenWidth-30, 2000);
        CGSize labelsize21 = [s21 sizeWithFont:font21 constrainedToSize:size21 lineBreakMode:NSLineBreakByCharWrapping];
        cell.DocNum.text =[NSString stringWithFormat:@"%@ ",  s21];
        
        cell.DocNum.textColor=[UIColor blackColor];
        cell.DocNum.frame=CGRectMake(15, 25, labelsize21.width+5,titleNemberfot);
        cell.DocNum.font= [UIFont fontWithName:@"Arial" size:titleNemberfot];
        
        NSString *twos = [NSString stringWithFormat:@"%@", @"两个"];
        UIFont *twofont = [UIFont systemFontOfSize:contenfot];
        CGSize twosize = CGSizeMake(320, 2000);
        CGSize twolabelsize = [twos sizeWithFont:twofont constrainedToSize:twosize lineBreakMode:NSLineBreakByCharWrapping];
        cell.GuideCode.text=[NSString stringWithFormat:@"%@", @"员工"];
        cell.GuideCode.font=[UIFont systemFontOfSize:contenfot];
        cell.GuideCode.textColor=zhonghuiColor;
        cell.GuideCode.frame=CGRectMake(15,  cell.DocNum.bottom+15,  twolabelsize.width+5, contenfot);
        
        NSString *s1 = [NSString stringWithFormat:@"￥%@", [commdity.Dict objectForKey:@"createName"]];
        UIFont *font1 = [UIFont systemFontOfSize:contenfot];
        CGSize size1 = CGSizeMake(ScreenWidth-30, 2000);
        CGSize labelsize1 = [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
        cell.GuideCode1.text=[NSString stringWithFormat:@"%@", [commdity.Dict objectForKey:@"createName"]];
        cell.GuideCode1.font=[UIFont systemFontOfSize:contenfot];
        cell.GuideCode1.textColor=shenhuicolor;
        cell.GuideCode1.frame=CGRectMake(cell.GuideCode.right,   cell.DocNum.bottom+15,  labelsize1.width, contenfot);
        
        cell.MemberCode.text=[NSString stringWithFormat:@"%@", @"日期"];
        cell.MemberCode.font=[UIFont systemFontOfSize:contenfot];
        cell.MemberCode.textColor=zhonghuiColor;
        cell.MemberCode.frame=CGRectMake(cell.GuideCode1.right,  cell.DocNum.bottom+15,  twolabelsize.width+5, contenfot);
        
        
        
        
        NSRange range={0,10};
        NSString* string =[[DocDate objectAtIndex:indexPath.row] substringWithRange:range];
        
        cell.MemberCode1.text=[NSString stringWithFormat:@"%@", string];
        
        cell.MemberCode1.font=[UIFont systemFontOfSize:contenfot];
        cell.MemberCode1.textColor=shenhuicolor;
        cell.MemberCode1.frame=CGRectMake(cell.MemberCode.right,  cell.DocNum.bottom+15,  200*ScreenWidth/750, contenfot);

        
//直接收款//////////
        
        if ([[orderType objectAtIndex:indexPath.row] isEqualToString:@"other"]) {
            cell.DocStatus.frame=CGRectMake(cell.DocNum.right, 27, 100, contenfot);
            cell.DocStatus.font=[UIFont systemFontOfSize:contenfot];
            
            
            if ([[orderStatus objectAtIndex:indexPath.row] isEqualToString:@"Y"]) {
                cell.DocStatus.textColor=luseColor;
                
                cell.DocStatus.text=@"自定义收全款";
            }
            
            
            cell.ItemName.text=[NSString stringWithFormat:@"%@", @"直接收款"];
            cell.ItemName.font=[UIFont systemFontOfSize:contenfot];
            cell.ItemName.textColor=zhonghuiColor;
            cell.ItemName.frame=CGRectMake(15,   cell.GuideCode.bottom+5,  120, contenfot);
            
        }
        
        
        
        if ([[orderType objectAtIndex:indexPath.row] isEqualToString:@"order"]) {
            cell.DocStatus.frame=CGRectMake(cell.DocNum.right,  27, 44, contenfot);
            cell.DocStatus.font=[UIFont systemFontOfSize:contenfot];
          if ([[orderStatus objectAtIndex:indexPath.row] isEqualToString:@"C"]) {
                cell.DocStatus.textColor=titleColor;
                cell.DocStatus.text=@"已取消";
            }if ([[orderStatus objectAtIndex:indexPath.row] isEqualToString:@"P"]) {
                cell.DocStatus.textColor=luseColor;
                cell.DocStatus.text=@"收定金";
            }
            if ([[orderStatus objectAtIndex:indexPath.row] isEqualToString:@"N"]) {
                cell.DocStatus.textColor=[UIColor colorWithRed:4/255.00 green:184/255.00 blue:149/255.00 alpha:1.0];
                cell.DocStatus.text=@"未收款";
            }
            if ([[orderStatus objectAtIndex:indexPath.row] isEqualToString:@"Y"]) {
                cell.DocStatus.textColor=luseColor;
                
                cell.DocStatus.text=@"收全款";
            }
            
            
        
//            
//            cell.Reasons.font=[UIFont systemFontOfSize:contenfot];
//            if ([[deliveryStatus objectAtIndex:indexPath.row] isEqualToString:@"N"]) {
//                cell.Reasons.textColor=hongsecolor;
//                cell.Reasons.text=[NSString stringWithFormat:@"%@",  @"未配送"];
//                cell.Reasons.frame=CGRectMake(cell.DocStatus.right,  27, 44, contenfot);
//            }if ([[deliveryStatus objectAtIndex:indexPath.row] isEqualToString:@"Y"]) {
//                cell.Reasons.textColor=luseColor;
//                cell.Reasons.text=[NSString stringWithFormat:@"%@",  @"已配送"];
//                 cell.Reasons.frame=CGRectMake(cell.DocStatus.right,  27, 44, contenfot);
//            }
//            if ([[deliveryStatus objectAtIndex:indexPath.row] isEqualToString:@"B"]) {
//                cell.Reasons.textColor=luseColor;
//                cell.Reasons.text=[NSString stringWithFormat:@"%@",  @"部分配送"];
//                 cell.Reasons.frame=CGRectMake(cell.DocStatus.right,  27, 60, contenfot);
//            }
//            if ([[deliveryStatus objectAtIndex:indexPath.row] isEqualToString:@"X"]) {
//                cell.Reasons.textColor=luseColor;
//                cell.Reasons.text=[NSString stringWithFormat:@"%@",  @"无需配送"];
//                 cell.Reasons.frame=CGRectMake(cell.DocStatus.right,  27, 60, contenfot);
//                
//            }
//            
//          
//            
//            cell.anzhuang.font=[UIFont systemFontOfSize:contenfot];
//            if ([[installStatus objectAtIndex:indexPath.row] isEqualToString:@"N"]) {
//                cell.anzhuang.textColor=hongsecolor;
//                cell.anzhuang.text=[NSString stringWithFormat:@"%@",  @"未安装"];
//                cell.anzhuang.frame=CGRectMake(cell.Reasons.right, 27, 44, contenfot);
//            }if ([[installStatus objectAtIndex:indexPath.row] isEqualToString:@"Y"]) {
//                cell.anzhuang.textColor=luseColor;
//                cell.anzhuang.text=[NSString stringWithFormat:@"%@",  @"已安装"];
//                cell.anzhuang.frame=CGRectMake(cell.Reasons.right, 27, 44, contenfot);
//            }
//            if ([[installStatus objectAtIndex:indexPath.row] isEqualToString:@"B"]) {
//                cell.anzhuang.textColor=luseColor;
//                cell.anzhuang.text=[NSString stringWithFormat:@"%@",  @"部分安装"];
//                cell.anzhuang.frame=CGRectMake(cell.Reasons.right, 27, 60, contenfot);
//            }
//            if ([[installStatus objectAtIndex:indexPath.row] isEqualToString:@"X"]) {
//                cell.anzhuang.textColor=luseColor;
//                cell.anzhuang.text=[NSString stringWithFormat:@"%@",  @"无需安装"];
//                cell.anzhuang.frame=CGRectMake(cell.Reasons.right, 27, 60, contenfot);
//                
//            }
            
            
            cell.ItemName.text=[NSString stringWithFormat:@"%@", @"购买"];
            cell.ItemName.font=[UIFont systemFontOfSize:contenfot];
            cell.ItemName.textColor=zhonghuiColor;
            cell.ItemName.frame=CGRectMake(15,  cell.GuideCode.bottom+5,  twolabelsize.width+5, contenfot);
            
            NSString *s12 = [NSString stringWithFormat:@"%@ %@件", [ItemName objectAtIndex:indexPath.row], [Number objectAtIndex:indexPath.row]];
            UIFont *font12 = [UIFont systemFontOfSize:contenfot];
            CGSize size12 = CGSizeMake(320, 2000);
            CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
            cell.ItemName1.text=[NSString stringWithFormat:@"%@ %@件", [ItemName objectAtIndex:indexPath.row], [Number objectAtIndex:indexPath.row]];
            cell.ItemName1.font=[UIFont systemFontOfSize:contenfot];
            cell.ItemName1.textColor=shenhuicolor;
            cell.ItemName1.frame=CGRectMake(cell.ItemName.right,  cell.GuideCode.bottom+5, labelsize12.width+15, contenfot);
            
        }
        
//service/////////////
        
        
        if ([[orderType objectAtIndex:indexPath.row] isEqualToString:@"service"]) {
            
            cell.DocStatus.frame=CGRectMake(cell.DocNum.right,  27, 160, contenfot);
            cell.DocStatus.font=[UIFont systemFontOfSize:contenfot];
            cell.DocStatus.textColor=hongsecolor;
            cell.DocStatus.text=[NSString stringWithFormat:@"%@", [serviceType objectAtIndex:indexPath.row]];
//            cell.Reasons.frame=CGRectMake(cell.DocStatus.right,  27, 60, contenfot);
//            cell.Reasons.font=[UIFont systemFontOfSize:contenfot];
//           
//            if ([[serviceStatus objectAtIndex:indexPath.row] isEqualToString:@"A"]) {
//                cell.Reasons.textColor=hongsecolor;
//                cell.Reasons.text=[NSString stringWithFormat:@"%@",  @"服务申请"];
//            }if ([[serviceStatus objectAtIndex:indexPath.row] isEqualToString:@"R"]) {
//                cell.Reasons.textColor=luseColor;
//                cell.Reasons.text=[NSString stringWithFormat:@"%@",  @"服务登记"];
//            }
//            if ([[serviceStatus objectAtIndex:indexPath.row] isEqualToString:@"C"]) {
//                cell.Reasons.textColor=luseColor;
//                cell.Reasons.text=[NSString stringWithFormat:@"%@",  @"服务确认"];
//            }
            
            
//            cell.anzhuang.frame=CGRectMake(cell.Reasons.right,  27, 55, contenfot);
//            
//            cell.anzhuang.font=[UIFont systemFontOfSize:contenfot];
//            cell.anzhuang.textAlignment=NSTextAlignmentCenter;
//            
//            if ([[payStatus objectAtIndex:indexPath.row] isEqualToString:@"N"]) {
//                cell.anzhuang.textColor=titleColor;
//                cell.anzhuang.text=@"";
//            }
//            if ([[payStatus objectAtIndex:indexPath.row] isEqualToString:@"Y"]) {
//                cell.anzhuang.textColor=luseColor;
//                
//                cell.anzhuang.text=@"";
//                
//            }
            
            cell.ItemName.text=[NSString stringWithFormat:@"%@", @"服务"];
            cell.ItemName.font=[UIFont systemFontOfSize:contenfot];
            cell.ItemName.textColor=zhonghuiColor;
            cell.ItemName.frame=CGRectMake(15,  cell.GuideCode.bottom+5,  twolabelsize.width+5, contenfot);
            NSString *s12 = [NSString stringWithFormat:@"%@ %@ %@件",cell.DocStatus.text, [itemTypes objectAtIndex:indexPath.row], [Number objectAtIndex:indexPath.row]];
            UIFont *font12 = [UIFont systemFontOfSize:contenfot];
            CGSize size12 = CGSizeMake(320, 2000);
            CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
            
            cell.ItemName1.text=[NSString stringWithFormat:@"%@ %@ %@件",cell.DocStatus.text, [itemTypes objectAtIndex:indexPath.row], [Number objectAtIndex:indexPath.row]];
            cell.ItemName1.font=[UIFont systemFontOfSize:contenfot];
            cell.ItemName1.textColor=shenhuicolor;
            cell.ItemName1.frame=CGRectMake(cell.ItemName.right, cell.GuideCode.bottom+5, labelsize12.width+15, contenfot);
        }
        
        
//refund////////////////
        
        if ([[orderType objectAtIndex:indexPath.row] isEqualToString:@"refund"]) {
            cell.DocStatus.frame=CGRectMake(cell.DocNum.right,  27, 160, contenfot);
            cell.DocStatus.font=[UIFont systemFontOfSize:contenfot];
           
            cell.DocStatus.textColor=hongsecolor;
            cell.DocStatus.text=[NSString stringWithFormat:@"%@",  [reasonType objectAtIndex:indexPath.row]];
            
            
            
//            cell.Reasons.frame=CGRectMake(cell.DocStatus.right,  27, 60, contenfot);
//            
//            cell.Reasons.font=[UIFont systemFontOfSize:contenfot];
//            if ([[refundType objectAtIndex:indexPath.row] isEqualToString:@"A"]) {
//                cell.Reasons.textColor=hongsecolor;
//                cell.Reasons.text=[NSString stringWithFormat:@"%@",  @"退货申请"];
//            }if ([[refundType objectAtIndex:indexPath.row] isEqualToString:@"R"]) {
//                cell.Reasons.textColor=luseColor;
//                cell.Reasons.text=[NSString stringWithFormat:@"%@",  @"退货登记"];
//            }
//            if ([[refundType objectAtIndex:indexPath.row] isEqualToString:@"C"]) {
//                cell.Reasons.textColor=luseColor;
//                cell.Reasons.text=[NSString stringWithFormat:@"%@",  @"退货确认"];
//            }
//            
//            
//            cell.anzhuang.frame=CGRectMake(cell.Reasons.right,27, 55, contenfot);
//            
//            cell.anzhuang.font=[UIFont systemFontOfSize:contenfot];
//          
//            
//            if ([[refundStatus objectAtIndex:indexPath.row] isEqualToString:@"N"]) {
//                cell.anzhuang.textColor=titleColor;
//                cell.anzhuang.text=@"";
//            }
//            if ([[refundStatus objectAtIndex:indexPath.row] isEqualToString:@"Y"]) {
//                cell.anzhuang.textColor=luseColor;
//                
//                cell.anzhuang.text=@"";
//                
//            }
            
            
            cell.ItemName.text=[NSString stringWithFormat:@"%@", @"退货"];
            cell.ItemName.font=[UIFont systemFontOfSize:contenfot];
            cell.ItemName.textColor=zhonghuiColor;
            cell.ItemName.frame=CGRectMake(15,   cell.GuideCode.bottom+5,  twolabelsize.width+5, contenfot);
            NSString *s12 = [NSString stringWithFormat:@"%@ %@件", [ItemName objectAtIndex:indexPath.row], [Number objectAtIndex:indexPath.row]];
            UIFont *font12 = [UIFont systemFontOfSize:contenfot];
            CGSize size12 = CGSizeMake(320, 2000);
            CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
            
            cell.ItemName1.text=[NSString stringWithFormat:@"%@ %@件", [ItemName objectAtIndex:indexPath.row], [Number objectAtIndex:indexPath.row]];
            cell.ItemName1.font=[UIFont systemFontOfSize:contenfot];
            cell.ItemName1.textColor=shenhuicolor;
            cell.ItemName1.frame=CGRectMake(cell.ItemName.right,cell.GuideCode.bottom+5, labelsize12.width+15, contenfot);
            
            
        }
        
        
        
        
        
        
        cell.DocTotal.text=[NSString stringWithFormat:@"%@", @"金额 ¥"];
        cell.DocTotal.font=[UIFont systemFontOfSize:contenfot];
        cell.DocTotal.textColor=zhonghuiColor;
        cell.DocTotal.frame=CGRectMake(cell.ItemName1.right,   cell.GuideCode.bottom+5, twolabelsize.width/2*3+2.5, contenfot);
        
        
        NSString*GoldPrice=[NSString stringWithFormat:@"%@",[DocTotal objectAtIndex:indexPath.row]];
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
        
        NSString *s = [NSString stringWithFormat:@"%@", formattedNumberString];
        UIFont *font = [UIFont systemFontOfSize:contenfot];
        CGSize size = CGSizeMake(320, 2000);
        CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
        
        cell.DocTotal1.text=[NSString stringWithFormat:@"%@", formattedNumberString];
        cell.DocTotal1.font=[UIFont systemFontOfSize:contenfot];
        cell.DocTotal1.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
        cell.DocTotal1.frame=CGRectMake(cell.DocTotal.right,  cell.GuideCode.bottom+5, labelsize.width+3, contenfot);
        
        
        
        
        if (DocNum.count !=indexPath.row+1) {
            UILabel *lineLabel21=[[UILabel alloc] initWithFrame:CGRectMake(15, 108-0.35, ScreenWidth-30, 0.35)];
            lineLabel21.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel21];
            
        }
        
        if (DocNum.count ==indexPath.row+1) {
            UILabel *lineLabel21=[[UILabel alloc] initWithFrame:CGRectMake(0,108-0.35, ScreenWidth, 0.35)];
            lineLabel21.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel21];
            
        }
    }
    

    
    if (tableView == table_list) {
        
         cell.detailTextLabel.font=[UIFont systemFontOfSize:15];
        cell.textLabel.font=[UIFont systemFontOfSize:16];
        cell.textLabel.textColor=qianheicolor;
        
        
        if(commdity.content3.length> 0)
            
        {
            if  ([[typeName objectAtIndex:indexPath.row]isEqualToString:commdity.content2]){
                
                
                
                
                if (![commdity.content3 isEqualToString:@"自定义"]) {
                    cell.detailTextLabel.text =commdity.content3;
                    
                    for (int i = 0; i<[[items objectAtIndex:indexPath.row]count]; i++) {
                        
                        if  ([[[[items objectAtIndex:indexPath.row]objectAtIndex:i]objectForKey:@"itemName"] isEqualToString:commdity.content3]){
                            
                            [current replaceObjectAtIndex:indexPath.row withObject:[[items objectAtIndex:indexPath.row]objectAtIndex:i]];
                            
                        }else{
                        }
                        
                    }
                    
                    
                }else{
                    
                    cell.detailTextLabel.text =[NSString stringWithFormat:@"%@~%@",openTimeTextFied.text,closeTimeTextFied.text];
                    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                    
                    [dic setValue:[NSString stringWithFormat:@"%@",@"Y"]forKey:@"isCustom"];
                    [dic setValue:[NSString stringWithFormat:@"%@",@"Y"] forKey:@"isRange"];
                    [dic setValue:[NSString stringWithFormat:@"%@",@"自定义"] forKey:@"itemName"];
                    [dic setValue:[NSString stringWithFormat:@"%@",@"other"] forKey:@"itemValue"];
                    [dic setValue:openTimeTextFied.text forKey:@"minValue"];
                    [dic setValue:closeTimeTextFied.text forKey:@"maxValue"];
                    
                    
                    
                    [current replaceObjectAtIndex:indexPath.row withObject:dic];
                    
                    
                    
                }
                
                
                NSLog(@"ffff====%@",typeCode);
                NSLog(@"====%@",isSingle);
                NSLog(@"====%@",current);
                
                
            }
            
            
        }else{
            
            
            cell = [[orderListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] ;
            cell.detailTextLabel.font=[UIFont systemFontOfSize:15];
            cell.textLabel.font=[UIFont systemFontOfSize:16];
            cell.textLabel.text =[NSString stringWithFormat:@"%@", [typeName objectAtIndex:indexPath.row]];
             UIButton*jiantou = [[UIButton alloc]init];
            jiantou.frame = CGRectMake(ScreenWidth-30,7.5, 30, 30);
            [jiantou setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
            cell.accessoryView=jiantou;
           cell.detailTextLabel.text = [[congzhicurrent objectAtIndex:indexPath.row]objectForKey:@"itemName"];
            
        }
        
        cell.detailTextLabel.textColor=luseColor;
        if (typeName.count !=indexPath.row+1) {
            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 55-0.35, ScreenWidth-30-45, 0.3)];
            lineLabel1.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel1];
            
        }
        
        if (typeName.count ==indexPath.row+1) {
           UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 55-0.35, ScreenWidth-30-45, 0.3)];
            lineLabel1.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel1];
            
        }
        
    }
    return cell;
}



- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == table_list) {
        return  55;
    }
    
    
    return  108;
    
}




#pragma mark - Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView == table_list) {
        commdity.content2=typeName[indexPath.row];
        
        
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        [mainScroll removeFromSuperview];
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"Token"];
        if (Token ==nil) {
            Token=@"dd";
        }
        NSMutableDictionary *param = [NSMutableDictionary new];
        [param setValue:Token forKey:@"Token"];
        
        mainScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(45, 0, ScreenWidth-45, ScreenHeight)];
        mainScroll.delegate = self;
        mainScroll.userInteractionEnabled = YES;
        mainScroll.scrollEnabled = YES;
        mainScroll.showsVerticalScrollIndicator = FALSE;
        mainScroll.showsHorizontalScrollIndicator = FALSE;
        mainScroll.backgroundColor=[UIColor whiteColor];
        [self.window addSubview:mainScroll];
        // 手势
        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad1)];
        singleFingerOne.numberOfTouchesRequired = 1; //手指数
        singleFingerOne.numberOfTapsRequired = 1; //tap次数
        singleFingerOne.delegate = self;
        [mainScroll addGestureRecognizer:singleFingerOne];
        UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenWidth-50, NavHeight-20)];
        title.text=typeName[indexPath.row];
        title.textAlignment=NSTextAlignmentCenter;
        [mainScroll addSubview:title];
        
        UIButton*quxiao1 = [[UIButton alloc] initWithFrame:CGRectMake(5, 20, 50, NavHeight-20)];
        [quxiao1 setTitle:@"取消" forState:UIControlStateNormal];
        [quxiao1 setTitleColor:zhonghuiColor forState:UIControlStateNormal];
        quxiao1.titleLabel.font=[UIFont systemFontOfSize:16];
        [quxiao1 addTarget:self action:@selector(quxiao1:) forControlEvents:UIControlEventTouchUpInside];
        [mainScroll addSubview:quxiao1];
        UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, NavHeight-0.35, ScreenWidth-45, 0.35)];
        line.backgroundColor=qianhuicolor;
        [mainScroll addSubview:line];
        
        
        arrrss=[[NSMutableArray alloc]init];
        
        arrrss=[[items objectAtIndex:indexPath.row] mutableCopy];
        
        NSLog(@"%@",arrrss);
        if (arrrss.count>0) {
            
            for (int i = 0; i<arrrss.count; i++) {
                
                daogouView = [[sxview alloc]initWithFrame:CGRectMake(15, NavHeight+(55*i), ScreenWidth-45, 55)];
                
                daogouView.buttonView.titleLabel.textAlignment=NSTextAlignmentRight;
                daogouView.buttonView.titleLabel.font=[UIFont systemFontOfSize:16];
                daogouView.buttonView.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
                [daogouView.buttonView setTitle: [[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemName"] forState:UIControlStateNormal];
                daogouView.buttonView.backgroundColor=[UIColor whiteColor];
                daogouView.buttonView.tag=i;
                [daogouView.buttonView setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                [daogouView.buttonView setTitleColor:qianheicolor forState:0];

                
                
                
                [mainScroll addSubview:daogouView];
                
                if ([[[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemName"] isEqualToString:@"自定义"]) {
                    
                    if ([typeName[indexPath.row] isEqualToString:@"时间"]) {
                        
                        [daogouView.buttonView setTitleColor:luseColor forState:0];
                        
                        UIButton*login = [[UIButton alloc] initWithFrame:CGRectMake(0, ScreenHeight-48, ScreenWidth-45, 48)];
                        [login setTitle:@"确认" forState:UIControlStateNormal];
                        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                        login.backgroundColor=luseColor;
                        [login addTarget:self action:@selector(queren:) forControlEvents:UIControlEventTouchUpInside];
                        [mainScroll addSubview:login];
                        
                        
                        
                        
                        _da = [[UIDatePicker alloc] init];
                        [_da addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
                        _da.datePickerMode = UIDatePickerModeDate;
                        _da.backgroundColor=[UIColor whiteColor];
                        
                        
                        openTimeTextFied=[[UITextField alloc]initWithFrame:CGRectMake(50,  daogouView.bottom-55, 110,  55)];
                        openTimeTextFied.borderStyle = UITextBorderStyleNone;
                        openTimeTextFied.font = [UIFont systemFontOfSize: contenfot];
                        openTimeTextFied.textColor=[UIColor blackColor];
                        openTimeTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                        openTimeTextFied.tag=2;
                        openTimeTextFied.placeholder = @"开始时间"; //默认显示的字
                        openTimeTextFied.delegate = self;
                        openTimeTextFied.text=commdity.opentime;
                        openTimeTextFied.textAlignment=NSTextAlignmentCenter;
                        [openTimeTextFied setUserInteractionEnabled:YES];
                        //openTimeTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                        [mainScroll addSubview:openTimeTextFied];
                        
                        UILabel* fuhao=[[UILabel alloc]initWithFrame:CGRectMake(openTimeTextFied.right, daogouView.bottom-55,15,55)];
                        fuhao.text=[NSString stringWithFormat:@"%@", @"～"];
                        fuhao.font=[UIFont systemFontOfSize:contenfot];
                        fuhao.textColor=[UIColor blackColor];
                        [mainScroll addSubview:fuhao];
                        
                        closeTimeTextFied=[[UITextField alloc]initWithFrame:CGRectMake(fuhao.right-5,  daogouView.bottom-55, 110,  55)];
                        closeTimeTextFied.borderStyle = UITextBorderStyleNone;
                        closeTimeTextFied.font = [UIFont systemFontOfSize: contenfot];
                        closeTimeTextFied.textColor=[UIColor blackColor];
                        closeTimeTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                        closeTimeTextFied.tag=3;
                        closeTimeTextFied.placeholder = @"结束时间"; //默认显示的字
                        closeTimeTextFied.textAlignment=NSTextAlignmentCenter;
                        closeTimeTextFied.text= commdity.closeTime;
                        closeTimeTextFied.delegate = self;
                        [closeTimeTextFied setUserInteractionEnabled:YES];
                        //                                   closeTimeTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                        [mainScroll addSubview:closeTimeTextFied];
                        //[_da setAccessibilityLanguage:@"Chinese"];
                        
                        openTimeTextFied.inputView = _da;
                        closeTimeTextFied.inputView = _da;
                        
                    }
                    
                    
                }else{
                    [daogouView.buttonView addTarget:self action:@selector(daogouView:) forControlEvents:UIControlEventTouchUpInside];
                }
                
                if ([[[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemName"] isEqualToString:cell.detailTextLabel.text]) {
                    
                    UIImageView*image=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-50-60, 16.5, 18, 18)];
                    image.image=[UIImage imageNamed:@"huiyuan_gou"];
                    
                    [daogouView addSubview:image];
                    
                }
            }
            
            
            
            
            [mainScroll setContentSize:CGSizeMake(ScreenWidth-45, daogouView.bottom)];
        }
        
        
        
        
        
    }else{
        
        
        commdity.orderId=orderId[indexPath.row];
        
        commdity.orderStatus=orderStatus[indexPath.row];
        commdity.deliveryStatus=deliveryStatus[indexPath.row];
        commdity.installStatus=installStatus[indexPath.row];
        
        
                if ([[orderType objectAtIndex:indexPath.row] isEqualToString:@"order"]) {
                    
                    commdity.orderId=orderId[indexPath.row];
                    
                    commdity.orderStatus=orderStatus[indexPath.row];
                    commdity.deliveryStatus=deliveryStatus[indexPath.row];
                    commdity.installStatus=installStatus[indexPath.row];
                    OrderDetailViewController *detailViewController = [[OrderDetailViewController alloc] init];
                    [self.navigationController pushViewController:detailViewController animated:YES];
                    
                }
                
                if ([[orderType objectAtIndex:indexPath.row] isEqualToString:@"service"]) {
                    commdity.orderId=orderId[indexPath.row];
                    ServiceDetailViewController *detailViewController = [[ServiceDetailViewController alloc] init];
                    [self.navigationController pushViewController:detailViewController animated:YES];
                    
                    
                    
                }
                if ([[orderType objectAtIndex:indexPath.row] isEqualToString:@"refund"]) {
                    commdity.orderId=orderId[indexPath.row];
                    RefundDetailViewController *detailViewController = [[RefundDetailViewController alloc] init];
                    [self.navigationController pushViewController:detailViewController animated:YES];
                    
                }
            }
    


}

- (void)dateChanged:(id)sender
{
    
    UIDatePicker* picker = (UIDatePicker*)sender;
    NSDateFormatter* df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd"];
    
    
    
    
    if ([openTimeTextFied isFirstResponder])
    {
        openTimeTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
        
        
        
    }else{
        
        closeTimeTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
    }
    
    
}

-(void)quxiao1:(UIButton*)sender{
    
    
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
    
    [mainScroll removeFromSuperview];
    
}
-(void)queren:(UIButton*)sender{
    
    if ([ openTimeTextFied.text length] < 1)
    {
        [self showAlertMessage:@"请选择开始时间"];
    }
    else
    {
        
        if ([closeTimeTextFied.text length] <1)
        {
            [self showAlertMessage:@"请选择结束时间"];
        }
        else{
            
            
            [mainScroll removeFromSuperview];
            commdity.content3=@"自定义";
            [table_list reloadData];
            commdity.opentime=openTimeTextFied.text;
            commdity.closeTime=closeTimeTextFied.text;
        }}
    
    
}

-(void)daogouView:(UIButton*)sender{
    
    commdity.opentime=nil;
    commdity.closeTime=nil;
    
    commdity.content3=sender.titleLabel.text;
    [mainScroll removeFromSuperview];
    [table_list reloadData];
    
    
    
}


-(void)sxuan:(UIButton*)sender{
    
    [self showAlertMessage:@"后台加参数key再配数据！"];
//    if(commdity.content3.length> 0){
//        
//        
//        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//        view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, ScreenHeight)];
//        view.backgroundColor=[UIColor blackColor];
//        view.alpha=0.5;
//        [self.window makeKeyAndVisible];
//        [self.window addSubview:view];
//        
//        
//        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
//        singleFingerOne.numberOfTouchesRequired = 1; //手指数
//        singleFingerOne.numberOfTapsRequired = 1; //tap次数
//        singleFingerOne.delegate = self;
//        [view addGestureRecognizer:singleFingerOne];
//        
//        table_list.frame=CGRectMake(45, 0, ScreenWidth-45, ScreenHeight);
//        [self.window addSubview:table_list];
//        UIButton*login = [[UIButton alloc] initWithFrame:CGRectMake(45, ScreenHeight-48, ScreenWidth-45, 48)];
//        [login setTitle:@"确认" forState:UIControlStateNormal];
//        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        login.backgroundColor=luseColor;
//        [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
//        [self.window addSubview:login];
//        
//        
//    }else{
//        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//        view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, ScreenHeight)];
//        view.backgroundColor=[UIColor blackColor];
//        view.alpha=0.5;
//        [self.window makeKeyAndVisible];
//        [self.window addSubview:view];
//        
//        
//        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
//        singleFingerOne.numberOfTouchesRequired = 1; //手指数
//        singleFingerOne.numberOfTapsRequired = 1; //tap次数
//        singleFingerOne.delegate = self;
//        [view addGestureRecognizer:singleFingerOne];
//        
//        
//         saveAccount1=NO;
        table_list = [[UITableView alloc]initWithFrame:CGRectMake(45, 0, ScreenWidth-45, ScreenHeight) style:UITableViewStylePlain];

//        table_list.delegate = self;
//        table_list.dataSource = self;
//        table_list.rowHeight = 60;
//        table_list.separatorStyle=UITableViewCellSeparatorStyleNone;
//        [self.window addSubview:table_list];
//        
//        
//        UIView*Header=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth-50, NavHeight)];
//        Header.backgroundColor=[UIColor whiteColor];
//        table_list.tableHeaderView=Header;
//        UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, NavHeight, ScreenWidth-50, 0.35)];
//        line.backgroundColor=qianhuicolor;
//        [Header addSubview:line];
//        
//        UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenWidth-50, NavHeight-20)];
//        title.text=@"筛选";
//        title.textAlignment=NSTextAlignmentCenter;
//        [Header addSubview:title];
//        
//        UIButton*quxiao = [[UIButton alloc] initWithFrame:CGRectMake(5, 20, 50, NavHeight-20)];
//        [quxiao setTitle:@"取消" forState:UIControlStateNormal];
//        [quxiao setTitleColor:zhonghuiColor forState:UIControlStateNormal];
//        quxiao.titleLabel.font=[UIFont systemFontOfSize:16];
//        [quxiao addTarget:self action:@selector(quxiao:) forControlEvents:UIControlEventTouchUpInside];
//        [Header addSubview:quxiao];
//        
//        UIButton*chongzhi = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-50-60, 20, 50, NavHeight-20)];
//        [chongzhi setTitle:@"重置" forState:UIControlStateNormal];
//        [chongzhi setTitleColor:luseColor forState:UIControlStateNormal];
//        chongzhi.titleLabel.font=[UIFont systemFontOfSize:16];
//        [chongzhi addTarget:self action:@selector(chongzhi:) forControlEvents:UIControlEventTouchUpInside];
//        [Header addSubview:chongzhi];
//        
//        UIButton*login = [[UIButton alloc] initWithFrame:CGRectMake(45, ScreenHeight-48, ScreenWidth-45, 48)];
//        [login setTitle:@"确认" forState:UIControlStateNormal];
//        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        login.backgroundColor=luseColor;
//        [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
//        [self.window addSubview:login];
//    }
}

-(void)chongzhi:(UIButton*)sender{
    [shaixuanBtn setTitleColor:shenhuicolor forState:UIControlStateNormal];
    [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
    commdity.content3=@"";
    current= [congzhicurrent mutableCopy];
    saveAccount1=NO;
    NSLog(@"----------%@",current);
    [table_list reloadData];
    
}

-(void)quxiao:(UIButton*)sender{
    
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
    
    [self.window makeKeyWindow ];
    self.window.hidden=YES;
    table_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-45, ScreenHeight);
    
    
}

-(void)login:(UIButton*)sender{
    
    [self.window makeKeyWindow ];
    self.window.hidden=YES;
    table_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-45, ScreenHeight);
    
    searchBeans=[NSMutableArray array];
    
    for (int i=0; i<current.count; i++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        NSString *typeCode1 = [typeCode objectAtIndex:i];
        NSString *isSingle1 = [isSingle objectAtIndex:i];
        NSString *typeName1 = [typeName objectAtIndex:i];
        NSString *dataType1 = [dataType objectAtIndex:i];
        NSMutableArray* currentarray=[NSMutableArray array];
        [currentarray insertObject:[current objectAtIndex:i] atIndex:0];
        [dic setValue:[NSString stringWithFormat:@"%@",typeCode1]forKey:@"typeCode"];
        [dic setValue:[NSString stringWithFormat:@"%@",isSingle1] forKey:@"isSingle"];
        [dic setValue:[NSString stringWithFormat:@"%@",typeName1] forKey:@"typeName"];
        [dic setValue:[NSString stringWithFormat:@"%@",dataType1] forKey:@"dataType"];
        [dic setValue:currentarray forKey:@"items"];
        [searchBeans addObject:dic];
    }
    
    NSLog(@"====%@",searchBeans);
    if ([commdity.content3 isEqualToString:@""]) {
        searchBeans=nil;
    }
    
    [self add];
    
    
}
-(void)closeKeyBoad1{
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
}
-(void)closeKeyBoad{
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
    [self.window makeKeyWindow ];
    self.window.hidden=YES;
    
    table_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-45, ScreenHeight);
    saveAccount=YES;
    
    [searchTextField resignFirstResponder];
}








-(void)peisongqueren:(UIButton*)sender{
//    [i12 removeFromSuperview];
//    [i22 removeFromSuperview];
//    [i1 removeFromSuperview];
//    if ([commdity.orderStatus isEqualToString:@"Y"]) {
//        if ([commdity.deliveryStatus isEqualToString:@"Y"]) {
//            [self showAlertMessage:@"此订单已经配送！"];
//        }
//        if ([commdity.deliveryStatus isEqualToString:@"X"]) {
//            [self showAlertMessage:@"此订单无需配送！"];
//        }
//        if ([commdity.deliveryStatus isEqualToString:@"N"]) {
//            
//            
//            DeliveryConfirmViewController  *generateVC=[[DeliveryConfirmViewController alloc] init];
//            [self.navigationController pushViewController:generateVC animated:YES];
//        }
//        if ([commdity.deliveryStatus isEqualToString:@"B"]) {
//            
//            
//            DeliveryConfirmViewController  *generateVC=[[DeliveryConfirmViewController alloc] init];
//            [self.navigationController pushViewController:generateVC animated:YES];
//        }
//        
//    }else{
//        [self showAlertMessage:@"此订单未收全款！"];
//    }
//    
    
}




-(void)sx:(UIButton*)sender{
    

}
#pragma mark  筛选后回调

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

////上拉刷新
//- (void)addheader
//{
//    MJRefreshHeaderView* footer = [MJRefreshHeaderView header];
//    footer.scrollView = _table;
//    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
//    {
//
//        //        [Global hideProgressHUDInternal:mainScroll];
//
//
//        //这里的RefreshView就是footer
//        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
//        //        NSLog(@"%@--->正在刷新", mainScroll.class);
//    };
//
//}

-(void)jiazai1{
    [jiazai removeFromSuperview];
    
    
}
@end

